<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-circle-plus-outline"
          size="small"
          @click.stop="handleEvaluate(scope.row)"
          v-if="scope.row.isSatisfaction==''"
        >任务评价
        </el-button>
       </template>
    </avue-crud>
        <!-- 评价-->
    <el-dialog title="评价"
                   append-to-body
                   :visible.sync="evaluateBoxShow"
                   width="50%">
    <el-form ref="EvaluateForm" :rules="rules" :model="evaluateForm" label-width="180px" size="mini">
     <el-card shadow="hover">
        <el-row>
          <el-col :span="24" v-show="false">
            <el-form-item label="id：" >
               <el-input :disabled="true" name="id"   v-model="evaluateForm.taskId"/>
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="任务：" >
               {{evaluateForm.taskName}}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="状态：" prop= "status">
               <el-radio-group :disabled="true" name="status" v-model="evaluateForm.status">
                <el-radio :label="1">正常</el-radio>
                <el-radio :label="2">异常</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
           <el-col :span="24" >
            <el-form-item label="执行情况：">
              {{evaluateForm.conditions}}
            </el-form-item>
          </el-col>
           <el-col :span="24" >
            <el-form-item label="执行人：" >
               {{evaluateForm.userName}}
            </el-form-item>
          </el-col>
           <el-col :span="24" >
            <el-form-item label="执行时间：" >
               {{evaluateForm.createTime}}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="附件：">
              
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="是否满意：" prop= "isSatisfaction">
               <el-radio-group name="isSatisfaction" v-model="evaluateForm.isSatisfaction">
                <el-radio label="y">满意</el-radio>
                <el-radio label="n">不满意</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
            <el-col :span="24" >
            <el-form-item label="任务评价：" >
               <el-input type="textarea"  name="evaluation"   v-model="evaluateForm.evaluation"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
              <el-form-item class="align-text:center">
                <el-button type="primary" @click="handleEvaluateSave('EvaluateForm')">保存</el-button>
                <el-button @click="handleCancel('EvaluateForm')">关闭</el-button>
              </el-form-item>
         </el-row>
     </el-card>
    </el-form>
    </el-dialog>
  </basic-container>
</template>

<script>
  import {getList, remove,evaluateSave} from "@/api/xapply/keyplace/taskEvaluate";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        form: {},
        evaluateForm: {},
        //Form表单校验
        rules: {
          isSatisfaction: [
            { required: true, message: '请选择是否满意', trigger: 'blur' }
          ],
         
        },
        query: {},
        evaluateBoxShow: false,
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height: 'auto',
          calcHeight: 30,
          dialogWidth: 850,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: false,
          selection: true,
          excelBtn: false,
          addBtn: false,
          editBtn: false,
          dialogClickModal: false,
          column: [
            {
              label: "主键",
              prop: "id",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
             {
              label: "场所",
              prop: "keyPlace",
              type: "select",
              span: 24,
              search: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              dicUrl: "/api/smart-xapply/keyplace/keyPlace/getList",
              props: {
                label: "title",
                value: "value"
              },
              rules: [{
                required: true,
                message: "请输入场所",
                trigger: "blur"
              }],
              hide: true,
            },
            {
              label: "任务",
              prop: "taskName",
              type: "input",
              span: 24,
            },
            {
              label: "执行情况",
              prop: "conditions",
              type: "textarea",
              overHidden: true,
              span: 24,
            },
           
           
            {
              label: "执行人",
              prop: "userName",
              type: "input",
              span: 24,
            },
            {
              label: "执行时间",
              prop: "createTime",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              span: 24,
            },
            
            {
              label: "状态",
              prop: "status",
              type: "select",
              span: 24,
              dicData: [
                  {
                    label: "正常",
                    value: 1
                  },
                  {
                    label: "异常",
                    value: 2
                  }
              ],
            },
             {
              label: "是否满意",
              prop: "isSatisfaction",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              dicData: [
                  {
                    label: "未评价",
                    value: ""
                  },
                  {
                    label: "满意",
                    value: "y"
                  },
                  {
                    label: "不满意",
                    value: "n"
                  }
              ],
            },
             {
              label: "任务评价",
              prop: "evaluation",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              overHidden: true,
            },
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.taskTaskdo_add, false),
          viewBtn: this.vaildData(this.permission.taskTaskdo_view, false),
          delBtn: this.vaildData(this.permission.taskTaskdo_delete, false),
          editBtn: this.vaildData(this.permission.taskTaskdo_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
     
     handleEvaluate(row){
        this.evaluateForm.id = row.id;
        this.evaluateForm.taskName = row.taskName;
        this.evaluateForm.status = row.status;
        this.evaluateForm.userName = row.userName;
        this.evaluateForm.conditions = row.conditions;
        this.evaluateForm.createTime = row.createTime;
        this.evaluateBoxShow = true;


     },
     handleEvaluateSave(form,loading){
       this.$refs[form].validate((valid) => {
            if (!valid){
              console.log('error submit!!');
              return false;
            }else{
               
                evaluateSave(this.evaluateForm.id,this.evaluateForm.isSatisfaction,this.evaluateForm.evaluation).then(() => {
                    this.onLoad(this.page);
                    this.$message({
                      type: "success",
                      message: "评价成功!"
                    });
                    this.evaluateBoxShow = false;
                    this.$refs['EvaluateForm'].resetFields();
                    this.onLoad(this.page);
                  }, error => {
                    loading();
                    window.console.log(error);
                  });
            }
       });
     },
      handleCancel(FormName){
        this.evaluateBoxShow = false;
        this.$refs[FormName].resetFields();
      },
      beforeOpen(done) {
        
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style>
</style>
